import 'package:flutter/material.dart';
import 'package:logger/logger.dart';

class PageViewTestRoute extends StatefulWidget {
  const PageViewTestRoute({Key? key}) : super(key: key);

  @override
  State<StatefulWidget> createState() => _PageViewTestRouteState();
}

class _PageViewTestRouteState extends State<PageViewTestRoute> {
  @override
  Widget build(BuildContext context) {
    var children = <Widget>[];
    // 生成 6 个 Tab 页
    for (int i = 0; i < 6; ++i) {
      children.add(MyPage(text: '$i'));
    }
    return Scaffold(
      appBar: AppBar(
        title: const Text('PageView'),
      ),
      body: PageView(
        children: children,
        allowImplicitScrolling: true,
      ),
    );
  }
}

class MyPage extends StatefulWidget {
  final String text;

  const MyPage({Key? key, required this.text}) : super(key: key);

  @override
  State<StatefulWidget> createState() => _MyPageState();
}

class _MyPageState extends State<MyPage> with AutomaticKeepAliveClientMixin  {
  final logger = Logger(printer: PrettyPrinter());

  @mustCallSuper
  @override
  Widget build(BuildContext context) {
    super.build(context);
    logger.i("build ${widget.text}");
    return Center(child: Text(widget.text, textScaleFactor: 5));
  }

  @override
  bool get wantKeepAlive => true;

}
